import { Color, MeshBasicMaterial, MeshBasicMaterialParameters } from "../../thirdparty/three/imports";
import { Texture3D } from "../textures/Texture3D";
import { Material3D } from "./Material3D";

export interface MeshBasicMaterial3D
{
    get _material(): MeshBasicMaterial;
    set _material(v: MeshBasicMaterial);
}

export class MeshBasicMaterial3D extends Material3D
{
    get color(): Color
    {
        return this._material.color;
    }
    set color(v)
    {
        this._material.color = v;
    }

    get map()
    {
        if (this._material)
        {
            this._map = Texture3D.get(this._material.map);
        }

        return this._map;
    }
    set map(v)
    {
        this._map = v;
        if (this._material)
        {
            this._material.map = v._texture;
        }
    }
    private _map: Texture3D;

    get envMap()
    {
        if (this._material)
        {
            this._envMap = Texture3D.get(this._material.envMap);
        }

        return this._envMap;
    }
    set envMap(v)
    {
        this._envMap = v;
        if (this._material)
        {
            this._material.envMap = v._texture;
        }
    }
    private _envMap: Texture3D;

    get wireframe()
    {
        return this._material.wireframe;
    }
    set wireframe(v)
    {
        this._material.wireframe = v;
    }

    constructor(parameters?: MeshBasicMaterialParameters)
    {
        super();
        this._material = new MeshBasicMaterial(parameters);
    }

    clone()
    {
        const meshBasicMaterial3D = new MeshBasicMaterial3D();
        meshBasicMaterial3D._material = this._material.clone();

        return meshBasicMaterial3D;
    }
}
